package com.easyui.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import com.easyui.bean.Student;
import com.easyui.common.SelProject;
import com.easyui.common.SelStudent;
import com.easyui.common.SelTeacher;

public class ChangeProgressServlet extends HttpServlet {
       
    public ChangeProgressServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}
		

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/json;charset=utf-8");
		response.setCharacterEncoding("UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		JSONObject jsonAll = null;
		boolean success = false;
		String msg = "";
		Map<String, Object> result = null;
		
		HttpSession session = request.getSession(); //获的session
		String role = (String)session.getAttribute("role");
		String tno = (String)session.getAttribute("userID");
		
		if(role != null && role.trim().equals("teacher")) {//登录身份为教师
			if(tno != null && !tno.trim().equals("")) {//获取到该老师工号
				int action = Integer.parseInt(request.getParameter("action"));
				int pno = Integer.parseInt(request.getParameter("pno"));
				
				if(action != -1) {
					result = new SelProject().changeProgress(pno, tno, action);
					if(result != null && result.size() > 0) {
						success = (Boolean)result.get("success");
						msg = result.get("msg").toString();
					} else {
						success = false;
						msg = "更改进度失败.";
					}
				} else {
					success = false;
					msg = "更改进度失败.";
				}

			} else {
				success = false;
				msg = "身份登录过期，请从新登录.";
			}
		} else {
			success = false;
			msg = "身份登录过期，请从新登录.";
		}

		jsonAll= new JSONObject();
		jsonAll.put("success", success);
		jsonAll.put("msg", msg);
		
		out.print(jsonAll);
		out.flush();
		out.close();
	}

}
